# -*- coding: utf-8 -*-
"""
@Time ： 2021/5/5 2:00
@Auth ： Mr. royalday 2487625775
@Company ： 2487625775@qq.cpm
@Function ：请输入模块功能描述
"""
from django.template import Library
from django.urls import reverse
from web import models

register = Library()


@register.inclusion_tag('inclusion/all_project_list.html')
def all_project_list(request):
    """
    项目页面，项目菜单下拉列表中显示：我创建的项目、我参与的项目
    :return:
    """
    # 我创建的所有项目
    my_project_list = models.Project.objects.filter(creator=request.tracer.user)

    # 我参与的所有项目
    my_join_project = models.ProjectUser.objects.filter(user=request.tracer.user)

    return {'my': my_project_list, "join": my_join_project, 'request': request}


@register.inclusion_tag('inclusion/manage_menu_list.html')
def manage_menu_list(request):
    """
    设置项目主页，默认选中菜单，如点击某个菜单时，该菜单在前端中显示选中状态
    :param request:
    :return:
    """
    data_list = [
        {'title': '概览', 'url': reverse('web:dashboard', kwargs={'project_id': request.tracer.project.id})},
        {'title': 'BUG', 'url': reverse('web:issues', kwargs={'project_id': request.tracer.project.id})},
        {'title': '统计', 'url': reverse('web:statistics', kwargs={'project_id': request.tracer.project.id})},
        {'title': 'wiki', 'url': reverse('web:wiki', kwargs={'project_id': request.tracer.project.id})},
        {'title': '文件', 'url': reverse('web:file', kwargs={'project_id': request.tracer.project.id})},
        {'title': '配置', 'url': reverse('web:setting', kwargs={'project_id': request.tracer.project.id})},
    ]

    # 判断当前路径是否处于列表中，如果是，给菜单添加上选中状态
    for item in data_list:
        if request.path_info.startswith(item['url']):
            item['class'] = 'active'
    return {'data_list': data_list}
